// i.d(t, { z: () => AnimatedNumber })
import n from "../math/79437"
import ObservableObject from "../observer/observable.object"
import Logger from "../utils/Logger"
const r = new Logger("animation")
export default class AnimatedNumber extends ObservableObject {
  _easing: (e: any, t: any, i: any, n: any) => any
  _active: boolean
  _elapsed: number
  _duration: number
  _endValue: any
  _delay: any
  startValue: number
  value: number
  _onComplete: any
  constructor(e, t?, i?, s = n.vG, r = 0) {
    super()
    this._easing = n.vG
    void 0 === t && (t = e), void 0 === i && ((this._active = !1), (i = 0), (this._elapsed = 0), (this._duration = 0)), this.modifyAnimation(e, t, i, s, 0, r)
  }
  get active() {
    return this._active
  }
  get duration() {
    return this._duration
  }
  get endValue() {
    return this._endValue
  }
  get easing() {
    return this._easing
  }
  get elapsed() {
    return this._elapsed
  }
  get delay() {
    return this._delay
  }
  tick(e: number) {
    if (!this._active) return this.endValue
    if (this._delay > 0) return (this._delay -= e), this.startValue
    const t = (this._elapsed + e) / Math.max(this._duration, 1e-5)
    return this.updateProgress(t), this.value
  }
  updateProgress(e) {
    if (isNaN(e)) return void r.error(`Invalid progress value: ${e}`)
    const t = Math.max(0, Math.min(e, 1)),
      i = this.active,
      n = this.value
    if (t >= 1)
      return (
        this.activate(!1),
        (this.value = this._easing(1, this.startValue, this._endValue - this.startValue, 1)),
        (this._elapsed = this.duration),
        this.commit(),
        void (this._onComplete && this._onComplete())
      )
    this.activate(!0),
      (this.value = this._easing(t, this.startValue, this._endValue - this.startValue, 1)),
      (this._elapsed = t * this.duration),
      (n === this.value && i === this.active) || this.commit()
  }
  updateAbsolute(e) {
    const t = e / Math.max(this._duration, 1e-5)
    this.updateProgress(t)
  }
  modifyAnimation(e, t, i, s = n.vG, r = 0, o = 0) {
    this._easing = s
    this._endValue = t
    this._duration = i
    this.activate(this._duration >= 0 && e !== t)
    this._elapsed = r
    this._delay = o
    this.startValue = e
    this.value = e
    this.commit()
    return this
  }
  onComplete(e) {
    return (this._onComplete = e), this
  }
  activate(e) {
    this._active = e
  }
  copy(e) {
    ;(this._endValue = e.endValue),
      (this._duration = e.duration),
      (this._active = e.active),
      (this._easing = e.easing),
      (this._elapsed = e.elapsed),
      (this.startValue = e.startValue),
      (this.value = e.value),
      this.commit()
  }
  clone() {
    const e = new AnimatedNumber(0)
    return e.copy(this), e
  }
  stop(e) {
    ;(this._active = !1), (this._elapsed = this._duration), (this.value = e), (this._endValue = e), this.commit()
  }
  equals(e) {
    return (
      this._active === e._active &&
      this.duration === e.duration &&
      this.easing === e.easing &&
      this.elapsed === e.elapsed &&
      this.endValue === e.endValue &&
      this.startValue === e.startValue &&
      this.value === e.value
    )
  }
}
